package com.wanmait.schedule.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.schedule.entity.StudentChange;
import com.wanmait.schedule.service.StudentChangeService;
import com.wanmait.schedule.util.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 学生调班表 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@RestController
@RequestMapping("/studentChange")
@RequiresPermissions("manage:student")
public class StudentChangeController {

    //调班学生列表
    @Resource
    private  StudentChangeService studentChangeService;

    //学生列表 分页  模糊搜索
    @PostMapping("list")
    public AjaxResult list(@RequestBody StudentChange studentChange,Integer pageNum){
        PageInfo<StudentChange> studentChangeList = studentChangeService.list(studentChange,pageNum);
        return AjaxResult.success("成功")
                .put("studentChangeList",studentChangeList);
    }
    //删除学生
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        studentChangeService.removeById(id);
        return AjaxResult.success("删除成功");
    }
    //修改学生
    @PostMapping("save")
    public AjaxResult save(@RequestBody StudentChange studentChange){
        studentChangeService.updateById(studentChange);
        return AjaxResult.success("修改成功");
    }

    //根据id读出来
    @PostMapping("findById/{id}")
    public AjaxResult FindById(@PathVariable("id") Integer id){
        StudentChange sc = studentChangeService.findByClassId(id);
        if(sc==null){
            return AjaxResult.error(10001,"失败" );
        }
        return AjaxResult.success("成功").put("studentChange",sc);
    }
}
